package com.example.christina.controller;

import com.example.christina.enity.Administrator;
import com.example.christina.repository.AdminRepository;
import com.example.christina.enity.Customer;
import com.example.christina.enity.Goods;
import com.example.christina.enity.Store;
import com.example.christina.service.AdminService;
import com.example.christina.service.CustomService;
import com.example.christina.service.GoodsService;
import com.example.christina.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private StoreService storeService;

    @Autowired
    private CustomService customService;


    @PostMapping(path = "addAdmin")
    public void addAdmin(@RequestBody Administrator administrator){
        adminService.addAdmin(administrator);
    }

    @DeleteMapping(path = "deleteAdmin")
    public void deleteAdmin(@RequestBody Administrator administrator){
        adminService.deleteAdmin(administrator);
    }

    @GetMapping(path = "getAllAdmins")
    public List<?> getAllAdmin(){
        return adminService.getAllAdmin();
    }

    @GetMapping(path = "getAdmin")
    public List<?> getAdmin(String adminname){
        return adminService.getAdmin(adminname);
    }

    @GetMapping(path = "getAllGoods")
    public List<?> getAllGoods(){
        //获取全部商品
        return goodsService.getAllGoods();
    }

    @DeleteMapping(path = "deleteGoods")
    public void deleteGoods(@RequestBody Goods goods){
        //管理员强制下架商品
        goodsService.deleteGoods(goods);
    }

    @DeleteMapping(path = "deleteStore")
    public void deleteStore(@RequestBody Store store){
        //管理员强制封印店家(*^▽^*)
        storeService.deleteStore(store);
    }

    @GetMapping(path = "getAllStores")
    public List<?> getAllStores(){
        //管理员查看所有在注册商家
        return storeService.getAllStores();
    }

    @GetMapping(path = "getAllCustoms")
    public List<?> getAllCustomes(){
        //管理员查看所有在注册用户
        return customService.getAllCustomers();
    }

    @DeleteMapping(path = "deleteCustomer")
    public void deleteCustomer(@RequestBody Customer customer){
        //管理员强制注销用户
        customService.deleteCustomer(customer);
    }

    @GetMapping(path = "getGoods")
    public List<?> getGoods(@RequestParam String store){
        //管理员查看某店铺的全部货物
        return goodsService.findBystorename(store);
    }

    @PostMapping(path = "updateGoods")
   public void updateGoods(@RequestBody Goods goods){
        //强行修改商品信息
        goodsService.addGoods(goods);
    }

}
